import React from 'react';
import ReactEcharts from '@/components/Echarts';

const getOption = data => ({
    series: [
        {
            name: '招聘需求职位分析',
            type: 'pie',
            radius: ['30%', '70%'],
            center: ['50%', '62%'],
            data,
            label: {
                normal: {
                    // TODO
                    fontSize: '14px',
                    formatter: '{b}\n{d}%'
                }
            },
            labelLine: {
                normal: {
                    lineStyle: {
                        color: 'rgba(0,0,0,.3)'
                    }
                }
            }
        }
    ]
});
/**
 *招聘需求职位分析
 */
const Position = ({ data }) => {
    let newData = [...data].sort((a, b) => b.value - a.value);
    if (newData.length > 10) {
        let num = 0;
        newData.slice(9, newData.length - 1).forEach(item => {
            num += Number(item.value);
        });
        const other = [
            {
                name: '其他',
                value: num
            }
        ];
        newData = newData.slice(0, 9).concat(other);
    }
    return <ReactEcharts option={getOption(newData)} />;
};

export default Position;
